//
//  ViewController.m
//  10604
//
//  Created by student on 16/3/5.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "ViewController.h"
#define kScreenWidth [UIScreen mainScreen].bounds.size.width
#define kScreenHeight [UIScreen mainScreen].bounds.size.height




@interface ViewController ()
@property (nonatomic,weak) UILabel *bigLabel;
@property (nonatomic,weak) UILabel *Label1;
@property (nonatomic,weak) UILabel *Label2;
@property (nonatomic,weak) UILabel *Label3;
@property (nonatomic,weak) UILabel *Label4;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.bigLabel = [self setUpLabelWithText:@"BigLabel" WithColor:[UIColor redColor] WithFrame:CGRectMake(20, 20, kScreenWidth - 40   , kScreenHeight/2 - 20)];
    self.Label1 = [self setUpLabelWithText:@"Action1" WithColor:[UIColor yellowColor] WithFrame:CGRectMake(20, kScreenHeight/2 + 20, kScreenWidth/2 - 40, 50)];
    self.Label2 = [self setUpLabelWithText:@"Action2" WithColor:[UIColor greenColor] WithFrame:CGRectMake(kScreenWidth/2 + 20, kScreenHeight/2 + 20, kScreenWidth/2 - 40, 50)];
    self.Label3 = [self setUpLabelWithText:@"Action3" WithColor:[UIColor blueColor] WithFrame:CGRectMake(20, kScreenHeight/2 + 120, kScreenWidth/2 - 40, 50)];
    self.Label4 = [self setUpLabelWithText:@"Action4" WithColor:[UIColor purpleColor] WithFrame:CGRectMake(kScreenWidth/2 + 20, kScreenHeight/2 + 120, kScreenWidth/2 - 40, 50)];
    
    
}



-(UILabel *)setUpLabelWithText:(NSString *)text
                WithColor:(UIColor *)color
                WithFrame:(CGRect)frame{
    UILabel *label = [[UILabel alloc] initWithFrame:frame];
    label.backgroundColor = color;
    label.text = text;
    [label setTextAlignment:NSTextAlignmentCenter];
    [self.view addSubview:label];
    return label;
}

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
    //横屏的时候
    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
        self.bigLabel.frame = CGRectMake(20, 20, kScreenHeight - 40, kScreenWidth/2 - 20);
        self.Label1.frame = CGRectMake(kScreenWidth/2 + 40, 20, kScreenHeight/2 - 40, 50);
        self.Label2.frame = CGRectMake(kScreenWidth/2 + 40, 90, kScreenHeight/2 - 40, 50);
        self.Label3.frame = CGRectMake(kScreenWidth/2 + 40, 160, kScreenHeight/2 - 40, 50);
        self.Label4.frame = CGRectMake(kScreenWidth/2 + 40, 230, kScreenHeight/2 - 40, 50);
        
    }
    else{
        for (UILabel *label in self.view.subviews) {
            [label removeFromSuperview];
        }
        [self viewDidLoad];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
